<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="myDiv"></div>
  </body>
  <script>
    let div = document.getElementById('myDiv'),event;
    div.addEventListener('myevent', (event) => {
      console.log('DIV: ' + event.detail);
    });
    document.addEventListener('myevent', (event) => {
      console.log('DOCUMENT: ' + event.detail);
    });
    if (document.implementation.hasFeature('CustomEvents', '3.0')) {
      event = document.createEvent('CustomEvent');
      event.initCustomEvent('myevent', true, false, 'Hello world!');
      div.dispatchEvent(event);
    }
    //   DIV: Hello world!
    //   DOCUMENT: Hello world!
  </script>

</html>
